#ifndef RTE_KB1285_EPAPER_H
#define RTE_KB1285_EPAPER_H

#include <Arduino.h>
#include <display.h>
#include "fonts.h"
#include "GUI_Paint.h"
#include <EPD.h>

class ePaper : public smodule {

public:

    int type() override { return pb_object_epaper_tag; }

    const char *name() override { return "ePaper"; }

    int encode(pb_object *object, pb_ostream_t *stream) override {
        object->object.epaper = data;
        object->which_object = pb_object_epaper_tag;
        return pb_encode(stream, pb_object_fields, object);
    }

    int iter(pb_field_iter_t *pS) override {
        return pb_field_iter_begin(pS, pb_epaper_info_fields, &data);
    }

    pb_epaper_info data;

    int begin(uint32_t tick) override;

#ifdef __PLATFORMIO_BUILD_DEBUG__
    int dev_test(uint32_t tick) override;
#endif

    int diag(uint32_t tick) override;

    int run(uint32_t tick) override;

    int drawString(char *string, int i, int i1, int i2);

    int drawFloat(float *pDouble, int i, int i1, int i2, int i3);

    int drawNumber(int i, int i1, int i2, int i3);

    void clear(int i);

    static void thd_epaper(const void *);


    int DrawTime(int i, int i1, PAINT_TIME *ptr);

    u8 _color = EPD_4IN01F_BLACK;
    u8 _color_bg = EPD_4IN01F_WHITE;

    void color(int val) { _color = val; }

    void color_bg(int val) { _color_bg = val; }

    sFONT *pFont = &Font24;

    void drawPixel(int i, int i1, u8 i2);

    void set_color(int i, u8 i1);

    void drawLine(int x1, int y1, int x2, int y2);

    void forceUpdate();


    int loop(uint32_t tick);

    void *lock;
};

extern ePaper displayer;
#endif // RTE_KB1285_EPAPER_H
